package com.yjs.app.trade.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;  
  
public class JsonDateValueProcessor implements JsonValueProcessor {  
  
    private String format ="yyyy-MM-dd HH:MM:SS";  
      
    @Override
    public Object processArrayValue(Object value, JsonConfig config) {  
        return process(value);  
    }  
  
    @Override
    public Object processObjectValue(String key, Object value, JsonConfig config) {  
        return processLong(value);  
    }  
      
    
    private Object process(Object value){  
          
        if(value instanceof Date){  
            SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.UK);  
            return sdf.format(value);  
        }  
        return value == null ? "" : value.toString();  
    }  
    
    private Object processLong(Object value){  
        if(value instanceof Date){  
            return ((Date)value).getTime();  
//        	return DateUtil.dateFormat.format((Date) value);
        } 
        /*else if (value instanceof BigDecimal) {
        	return new BigDecimal(value.toString()).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString();
        }*/
        return value == null ? "" : value.toString();  
    } 
}  
